// 登录前的引导页
import React, { useState, useEffect } from 'react';
import { connect, history } from 'umi';
import { Spin, Image } from 'antd';
import { LoadingOutlined } from '@ant-design/icons';

const LayoutMask = (props) => {
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    setTimeout(() => {
      const token = localStorage.getItem('token');
      if (!token) {
        history.push(`/login`);
      } else {
        setLoading(false);
      }
    }, 0);
  }, []);

  return (
    <>
      {loading && (
        <Spin
          spinning={loading}
          style={{ width: '100%' }}
          indicator={<LoadingOutlined style={{ fontSize: 36 }} spin />}
          size="large"
        >
        </Spin>
      )}
    </>
  );
};

export default connect(({ history }) => ({ history }))(LayoutMask);
